﻿<Serializable()> _
Public Class UI
    Inherits BaseDominio

    Private _ehFixo As Boolean
    <Obsolete("Implementar")> _
    Public Overridable Property EhFixo() As Boolean
        Get
            'TODO : EhFixo
            Return True
        End Get
        Set(ByVal value As Boolean)
            _ehFixo = value
        End Set
    End Property

    Private _nome As String
    Public Overridable Property Nome() As String
        Get
            Return _nome
        End Get
        Set(ByVal value As String)
            _nome = value
        End Set
    End Property

    Private _descricao As String
    Public Overridable Property Descricao() As String
        Get
            Return _descricao
        End Get
        Set(ByVal value As String)
            _descricao = value
        End Set
    End Property


    Private _measuredH As Integer
    Public Overridable Property measuredH() As Integer
        Get
            Return _measuredH
        End Get
        Set(ByVal value As Integer)
            _measuredH = value
        End Set
    End Property

    Private _measuredW As Integer
    Public Overridable Property measuredW() As Integer
        Get
            Return _measuredW
        End Get
        Set(ByVal value As Integer)
            _measuredW = value
        End Set
    End Property

    Private _itens As IList(Of ItemUI)
    Public Overridable Property Itens() As IList(Of ItemUI)
        Get
            Return _itens
        End Get
        Set(ByVal value As IList(Of ItemUI))
            _itens = value
        End Set
    End Property

#Region "Negocio"

    Public Sub New()
        MyBase.New()
    End Sub

    Public Sub New(ByVal _mockup As mockup)
        MyBase.New()

        With _mockup
            Me.measuredH = .measuredH
            Me.measuredW = .measuredW
            If _mockup.Controls IsNot Nothing Then
                Me.Itens = New List(Of ItemUI)

                For Each _control In _mockup.Controls
                    Me.Itens.Add(New ItemUI(_control, Me))
                Next
            End If

        End With

    End Sub

    Public Overridable Function Buscar(ByVal _id As Long) As UI
        Return MyBase.UIDao.Buscar(_id)
    End Function

    Public Overridable Sub Salvar()
        MyBase.UIDao.Salvar(Me)
    End Sub

    Public Overridable Function GerarHTML(ByVal _tipoTemplate As TipoTemplate) As String

        Dim _html As String = String.Empty

        _html = HTMLs.CabecalhoHTML

        For Each _item In Me.Itens
            _html &= _item.GerarHTML(_tipoTemplate) & vbCrLf
        Next

        _html &= HTMLs.RodapeHTML

        Return _html
    End Function

    Public Overridable Sub GerarArquivoHTML(ByVal _pathEArquivo As String)

        Dim _streamWriter As IO.StreamWriter

        _streamWriter = IO.File.CreateText(_pathEArquivo)
        Try
            _streamWriter.WriteLine(Me.GerarHTML(TipoTemplate.HTML))
            '_streamWriter.WriteLine("<hr />")
            '_streamWriter.WriteLine(Me.GerarHTML(TipoTemplate.AjaxControlToolkit))
            '_streamWriter.WriteLine("<hr />")
            '_streamWriter.WriteLine(Me.GerarHTML(TipoTemplate.HTMLEncoded))
            _streamWriter.Flush()
        Finally
            _streamWriter.Close()
        End Try

    End Sub




#End Region

End Class



